﻿//出货单子打印
//作者:喻涛林 2009.2
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Comod_DrawPrint : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                ZSql zsql = new ZSql();
                ZSql count = new ZSql();
                ZSql man = new ZSql();
                string sql = "select brand,comodname,modul,unit,number,prices,gifts,guestName,GuestMan,phone,address,TotalMoney,convert(varchar(10),DeliveryDate,120) as DeliveryDate,SalesContent,userId from CS_Sales  a join CS_Guest b on a.guestid=b.GuestId where SalesCode='" + Request.QueryString["id"].ToString() + "'";
                count.Open("select sum(number)as num,sum(TotalMoney)as price from CS_Sales where SalesCode='" + Request["id"] + "' group by SalesCode");
                man.Open("select OutMan,DeliveryMan, convert(varchar(10),OutDate,120) as OutDate from CS_OutManage where OutBarCode='" + Request["id"] + "'");
                zsql.Open(sql);
                //Response.Write(sql);
                DataTable dt = new DataTable();
                string strTable = "";
                dt = zsql.m_table;
                int a = 0;
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {   
                        strTable += "<table width=\"97%\"  border=\"0\"><tr><td class=\"F_size18 F_B\" align=\"center\">重庆市南川区协和家电有限公司</td></tr></table>";
                        strTable += "<table width=\"97%\" height=40 border=\"0\" align=\"center\"><tr><td width=\"43%\">&nbsp;</td><td  class=\"F_size16 F_B \">商品配送单</td><td  align=\"right\"></td></tr></table>";


                        strTable += "<table width=\"97%\" align=\"center\" ><tr><td align=\"left\" width=\"35%\">用户姓名：" + zsql.m_table.Rows[0]["GuestMan"].ToString() + "</td><td align=\"left\" width=\"35%\">送货日期：" + zsql.m_table.Rows[0]["DeliveryDate"].ToString() + "</td><td align=\"left\"><span class=\"nobr\">联系电话：" + zsql.m_table.Rows[0]["phone"].ToString() + "</span></td></tr><tr><td  width=\"70%\" align=\"left\" colspan=\"2\" >联系地址：" + zsql.m_table.Rows[0]["address"].ToString() + "</td><td align=\"left\">销售备注：" + zsql.m_table.Rows[0]["SalesContent"].ToString() + "</td></tr></table>";
                        //strTable += "<table width=\"100%\" border=\"0\"><tr><td width=\"7%\">摘要：</td><td width=\"46%\">" + zsql.m_table.Rows[0]["gifts"].ToString() + "</td><td width=\"7%\">备注：</td><td width=\"40%\">" + zsql.m_table.Rows[0]["SalesContent"].ToString() + "</td> </tr></table>";

                        strTable += "<table width=\"97%\" align=\"center\" border=\"1\"><tr><td align=\"center\">品牌</td><td align=\"center\">商品名称</td><td align=\"center\">规格及型号</td><td align=\"center\">数量</td><td align=\"center\">单位</td><td align=\"center\">单价</td><td align=\"center\">金额</td><td>备注</td></tr>";


                        for (int i = 0; i < zsql.m_table.Rows.Count; i++)
                        {
                            strTable += "<tr><td align=\"center\">" + zsql.m_table.Rows[i]["brand"].ToString() + "</td><td align=\"center\">" + zsql.m_table.Rows[i]["comodName"].ToString() + "</td><td align=\"center\">" + zsql.m_table.Rows[i]["modul"].ToString() + "</td><td align=\"center\">" + zsql.m_table.Rows[i]["number"].ToString() + "</td><td align=\"center\">" + zsql.m_table.Rows[i]["unit"].ToString() + "</td><td align=\"right\">" + zsql.m_table.Rows[i]["prices"].ToString().Substring(0, zsql.m_table.Rows[i]["prices"].ToString().Length - 2) + "</td><td align=\"right\">" + zsql.m_table.Rows[i]["TotalMoney"].ToString().Substring(0, zsql.m_table.Rows[i]["TotalMoney"].ToString().Length - 2) + "</td><td>&nbsp;</td></tr>";
                            a++;
                        }

                        for (; a < 6; a++)//补充表格
                        {
                            strTable += "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
                        }

                        strTable += " <tr><th colspan=\"2\">本页小计</th><td colspan=\"3\">" + count.m_table.Rows[0]["num"].ToString() + "</td><td colspan=\"2\">" + count.m_table.Rows[0]["price"].ToString().Substring(0, count.m_table.Rows[0]["price"].ToString().Length - 2) + "</td></tr><tr><th colspan=\"2\">本单合计</th><td colspan=\"3\">" + count.m_table.Rows[0]["num"].ToString() + "</td><td colspan=\"2\">" + count.m_table.Rows[0]["price"].ToString().Substring(0, count.m_table.Rows[0]["price"].ToString().Length - 2) + "</td></tr></table>";
                        if (man.m_table.Rows.Count > 0)
                        {
                            strTable += "<table width=\"97%\" border=\"0\"  align=\"center\"><tr><td colspan=\"5\"><font color=\"#FF0000\"><p>请您仔细核对商品型号、数量、金额是否一致。白色存根联、红色用户联。(用户签字有效)</p></font></td></tr><tr><td  align=\"left\">库管员：</td><td >" + man.m_table.Rows[0]["OutMan"].ToString() + "</td><td align=\"left\">配送员：" + man.m_table.Rows[0]["DeliveryMan"].ToString() + "</td> <td align=\"left\">出库日期：" + man.m_table.Rows[0]["OutDate"].ToString() + "</td> <td align=\"left\">服务电话：023-71459999</td><td align=\"left\">用户签字：</td><td>&nbsp;</td></tr></table>";
                        }
                    }
                }
                zsql.Close();
                count.Close();
                lblTable.Text = strTable;
            }
        }
    }
}
